#include "rankingview.h"
#include "ui_rankingview.h"

RankingView::RankingView(QWidget *parent) :
    QWidget(parent,Qt::FramelessWindowHint),
    ui(new Ui::RankingView)
{
    ui->setupUi(this);

    startDis = 0;
    this->ui->scoreLabel->setText("The score is:");

    QTimer *timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(timerUpdate()));
    timer->start(10);

}

RankingView::~RankingView()
{
    delete ui;
}

void RankingView::timerUpdate()
{
    this->ui->userLabel->setText(userName.toString());
    this->ui->scorePlay->setText(score.toString());
    QString content = "";

    if(startDis.toInt())
    {
        fileContent = FileProcess::fileRead("D:/Qtcase/2048Game/ranking.txt");
        content = FileProcess::update( fileContent, userName, score);
        this->ui->textRanking->setText(content);
        fileContent.clear();
    }
}


void RankingView::on_btnRestart_clicked()
{
    startDis = 0;
    emit RenewSignal();

    QString StrText = ui->textRanking->toPlainText();
    FileProcess::fileWrite("D:/Qtcase/2048Game/ranking.txt",StrText);

}

void RankingView::on_btnExit_clicked()
{
    startDis = 0;
    QString StrText = ui->textRanking->toPlainText();
    FileProcess::fileWrite("D:/Qtcase/2048Game/ranking.txt",StrText);
    emit ExitSignal();
}
